﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Database;
using System.Data;
public partial class User : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        getHotProduct();
        if (!IsPostBack)
        {

            HienThiHangSX();

            if (Session["tenkh"] == null)
            {
                Panel_dangnhap.Visible = true;
                Panel_dangxuat.Visible = false;
            }
            else
            {
                Panel_dangnhap.Visible = false;
                Panel_dangxuat.Visible = true;
                lb_tenkhachhang.Text = Session["tenkh"].ToString();
            }


        }
        if (Session["ShoppingCart"] == null)
        {
            itemCount.Text = "0";
        }
        else
        {
            ShoppingCart.Cart cart = (ShoppingCart.Cart)Session["ShoppingCart"];
            int num = cart.Count;
            itemCount.Text = Convert.ToString(num);
        }
    }
    public void getHotProduct()
    {
        MayTinh mt = new MayTinh();
        DataTable ds = mt.DSMTBC();
        rptImages.DataSource = ds;
        rptImages.DataBind();

    }
    protected void tenkh_TextChanged(object sender, EventArgs e)
    {
        tenkh.Text = "";
    }

    void HienThiHangSX()
    {
        HangSX hsx = new HangSX();
        Repeater1.DataSource = hsx.DSNhaSanXuat();
        Repeater1.DataBind();
    }

    protected void logout_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        Panel_dangnhap.Visible = true;
        Panel_dangxuat.Visible = false;
        string links = Request.ServerVariables["HTTP_REFERER"].ToString();
        Response.Redirect(links);
    }
    protected void login_Click(object sender, EventArgs e)
    {
        string tenDangNhap = tenkh.Text;
        string pass = matkhau.Text;
        KhachHang kh = new KhachHang();
        DataTable table = kh.DangNhap(tenDangNhap, pass);
        if (table.Rows.Count > 0)
        {
            Session["tenkh"] = table.Rows[0]["tenkh"];
            lb_tenkhachhang.Text = table.Rows[0]["tenkh"].ToString();
            Panel_dangnhap.Visible = false;
            Panel_dangxuat.Visible = true;
            string links = Request.ServerVariables["HTTP_REFERER"].ToString();
            Response.Redirect(links);
        }
        else
        {
            loi.Visible = true;
            loi.Text = "Đăng Nhập Thất Bại";
        }
    }
    
}
